package com.blacktea.behavioralpatterns.visitorpattern;

/**
 * @description: 订单打印访问者类
 * @author: black tea
 * @date: 2023/3/26 22:42
 */
public class OrderPrintVisitor implements OrderVisitor {

    private final StringBuilder builder = new StringBuilder();

    @Override
    public void visit(ProductOrderItem item) {
        builder.append(item.getQuantity()).append(" x ")
                .append(item.getName()).append(": ")
                .append(item.getPrice()).append("\n");
    }

    @Override
    public void visit(DiscountOrderItem item) {
        builder.append("折扣: ").append(item.getDiscount()).append("%\n");
    }

    @Override
    public String getResult() {
        return builder.toString();
    }
}
